<template>
  <div>
    <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />
    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
    </div>
  </div>
</template>
<script>
import {addSave,getAllbrand,getAllseriess,getAllmodels,getAllpackage,getAlloption,getAllInterior,getAllexterior} from '@/api/omSale/vehicleParameters/materialPrice/index.js'
import { dictionary } from '@/utils/dictMixin';
import moment from 'moment'
export default {
  data(){
    this.saveData=null;
    return{
      formList:this.createdFrom(),
      seriesList:[]
    }
  },
  props:['rowData'],
  created(){
    this.getList()
    this.getDetail(this.rowData)
  },
  mixins:[dictionary],
  methods:{
    createdFrom(){
      return [
        {
          type: 'SELECT',
          label: '品牌名称',
          fieldName: 'brandId',
          placeholder: '请输入...',
          itemList:[],
          disabled:true,

        },
        {
          type: 'SELECT',
          label: '车系名称',
          fieldName: 'seriesId',
          placeholder: '请输入...',
          itemList:[],
          disabled:true,
        },
        {
          type: 'SELECT',
          label: '车型名称',
          fieldName: 'modelId',
          placeholder: '请选择...',
          itemList: [],
          disabled:true,
        },
        {
          type: 'SELECT',
          label: '配置名称',
          fieldName: 'packageId',
          placeholder: '请选择..',
          itemList:[],
          disabled:true,
        },
        {
          type: 'SELECT',
          label: '选装名称',
          fieldName: 'optionId',
          placeholder: '请选择',
          itemList:[],
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '产品代码',
          fieldName: 'productCode',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '产品名称',
          fieldName: 'productName',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'SELECT',
          label: '年款',
          fieldName: 'yearModel',
          placeholder: '请选择',
          itemList:this.createDictList('6048'),
          disabled:true,
        },
        {
          type: 'SELECT',
          label: '内饰',
          fieldName: 'trimColorId',
          placeholder: '请选择',
          itemList:[],
          disabled:true,
        },
        {
          type: 'SELECT',
          label: '外饰',
          fieldName: 'colorId',
          placeholder: '请选择',
          itemList:[],
          disabled:true,
        },
        {
          type: 'SELECT',
          label: '排放标准',
          fieldName: 'dischargeStandard',
          placeholder: '请选择',
          initialValue:'',
          hidden:true,
          itemList:this.createDictList('1510'),
          disabled:true,
        },


        {
          type: 'SELECT',
          label: '变速箱',
          fieldName: 'transMission',
          placeholder: '请选择',
          initialValue:'',
          disabled:true,
          hidden:true,
          itemList:this.createDictList('6049')
        },
        {
          type: 'SELECT',
          label: '排量',
          fieldName: 'disPlacement',
          placeholder: '请选择',
          initialValue:'',
          hidden:true,
          disabled:true,
          itemList:this.createDictList('6050')
        },

        {
          type: 'INPUT',
          label: '市场指导价',
          fieldName: 'oemDirectivePrice',
          placeholder: '请选择',
          disabled:true,
          initialValue:'',
        },
        {
          type: 'SELECT',
          label: '是否可订购',
          fieldName: 'orderStatus',
          placeholder: '请选择',
          itemList:this.createDictList('1004'),
          disabled:true,
        },
        {
          type: 'DATE',
          label: '启用日期',
          fieldName: 'startDate',
          placeholder: '请选择',
          dateType:'exactdate',
          initialValue:moment().format('YYYY-MM-DD'),
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '国补标准',
          fieldName: 'subsidyAmount',
          placeholder: '请选择',
          disabled:true,
          initialValue:'',
        },
        {
          type: 'SELECT',
          label: '续航里程',
          fieldName: 'enduranceMileage',
          placeholder: '请选择',
          initialValue:'',
          hidden:true,
          disabled:true,
          itemList:this.createDictList('6051'),
        },
        {
          type: 'SELECT',
          label: '是否下发',
          fieldName: 'isIssue',
          placeholder: '请选择',
          initialValue:'',
          disabled:true,
          itemList:this.createDictList('1004'),
        },
      ]
    },
    changeHandle(val){
      this.saveData=val;
    },
    async getList(){
      let res=await getAllbrand();
      let res1=await getAllInterior();
      let res2=await getAllexterior();
      this.formList.find(x=>x.fieldName=='brandId').itemList=res.data.map(x=>({text:x.brandName,value:x.brandId}))
      this.formList.find(x=>x.fieldName=='colorId').itemList=res2.data.map(x=>({text:x.colorName,value:x.colorId}))
      this.formList.find(x=>x.fieldName=='trimColorId').itemList=res1.data.map(x=>({text:x.colorName,value:x.colorId}))
    },
    async getDetail(data){

      let res=await getAllseriess({brandId:data.brandId})
      this.seriesList=res.data;
      this.formList.find(x=>x.fieldName=='seriesId').itemList=res.data.map(x=>({text:x.seriesName,value:x.seriesId}))
      let res2=await getAllmodels({brandId:data.brandId,seriesId:data.seriesId})
      this.formList.find(x=>x.fieldName=='modelId').itemList=res2.data.map(x=>({text:x.modelName,value:x.modelId}))
      let res1=await getAllpackage({brandId:data.brandId,seriesId:data.seriesId,modelId:data.modelId})
      this.formList.find(x=>x.fieldName=='packageId').itemList=res1.data.map(x=>({text:x.configName,value:x.packageId}))
      let res3=await getAlloption({brandId:data.brandId,seriesId:data.seriesId,modelId:data.modelId,packageId:data.packageId})
      this.formList.find(x=>x.fieldName=='optionId').itemList=res3.data.map(x=>({text:x.optionName,value:x.optionId}))
      let powerType=''
      this.seriesList.map(x=>{
        if(data.seriesId==x.seriesId){
          powerType=x.powerType
        }
      })
      for(let i in data){
        this.formList.map(x=>{
          if(x.fieldName==i){
            x.initialValue=data[i]
          }
        })
      }
      if(powerType==60081001){
        // 燃油车
        this.formList.find(x=>x.fieldName=='enduranceMileage').hidden=true;
        this.formList.find(x=>x.fieldName=='dischargeStandard').hidden=false;
        this.formList.find(x=>x.fieldName=='transMission').hidden=false;
        this.formList.find(x=>x.fieldName=='disPlacement').hidden=false;
      }else{
        this.formList.find(x=>x.fieldName=='enduranceMileage').hidden=false;
        this.formList.find(x=>x.fieldName=='dischargeStandard').hidden=true;
        this.formList.find(x=>x.fieldName=='transMission').hidden=true;
        this.formList.find(x=>x.fieldName=='disPlacement').hidden=true;
      }
    },
    async closeDrawer(type){
      if(type==1){
        this.$emit('close')
      }
    }
  }
}
</script>
